﻿Imports BUS
Imports DTO

Public Class FormChonThucDon

    Public _maThucDon As Integer = 0
    Public _soLuong As Integer = 0
    Public _flag As Integer = 0
    Dim _thucDonBUS As New ThucDonBUS()        

    Private Sub FormChonThucDon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadThucDon()
    End Sub

    Public Sub LoadThucDon()
        Dim _listThucDon As New List(Of ThucDonDTO)
        _listThucDon = _thucDonBUS.LoadListThucDonBUS()
        Dim stt As Integer = 1

        lvThucDon.Items.Clear()
        For Each _thucDon As ThucDonDTO In _listThucDon

            Dim itemListView As New ListViewItem(_thucDon.MaMenu.ToString())
            itemListView.SubItems.Add(stt)
            itemListView.SubItems.Add(_thucDon.Ten)
            itemListView.SubItems.Add(_thucDon.DonGia)
            itemListView.SubItems.Add(_thucDon.TinhTrang)
            lvThucDon.Items.Add(itemListView)
            stt += 1
        Next

    End Sub

    Private Sub btnChon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChon.Click
        _flag = 1
        If (lvThucDon.SelectedItems.Count = 0) Then
            MessageBox.Show("Mời bạn chọn 1 món trong list thực đơn")
            Return
        End If
        Dim _itemLv As ListViewItem = lvThucDon.SelectedItems(0)
        If (nudSoLuong.Value > Integer.Parse(_itemLv.SubItems(4).Text)) Then
            MessageBox.Show("Vượt quá số lượng quy định")
        Else
            _maThucDon = Integer.Parse(_itemLv.Text)
            _soLuong = nudSoLuong.Value
            Me.Close()
        End If


    End Sub

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Me.Close()
    End Sub
End Class